Script files must be stored in the folder called "Scripts", in the same folder as Pfhorte. Any script file name starting with "#" will not appear in the scripting menu. This allows you to have scripts that are only meant to be called by other scripts private. Scripts are stored as text files with one script command per line. All script commands and variables are case sensitive, so be sure to check your spelling.
To execute a script, you must have a line selected. The Pen is positioned at the first point on this line and its angle is set to point to the second point.
There are several variables available to be examined and changed by the scripts. These variables affect the way polygons are created, among other things. There are some general purpose variables that you can use for your own purposes. The scripting commands will be divided up into flow control commands, and general commands.
Look at the scripts that come with Pfhorte for an example of how to write them. Please note that this scripting system has been entirely re-done, so there are sure to be bugs, so be careful and report them to me.
Flow Control Commands
If (booleanExpression), Else, Endif
These commands allow you to have conditional execution of your scripts. If the booleanExpression in the If statement evaluates to true, then the statements between the If and the Else will be executed, otherwise the statements between the Else and the Endif will be executed. The Else statement is optional.
While (booleanExpression), EndWhile
These statements allow you to perform a series of operations over and over until the booleanExpression is false. While the booleanExpression is true, the statements between the While and EndWhile are executed.
Repeat, Until (booleanExpression)
These statements allow you to perform a series of operations over and over until the booleanExpression is true. While the booleanExpression is false, the statements between the Repeat and Until are executed.
Gosub name, Subroutine name, EndSub
These statements allow you to group othen executed scripting commands into one command. Whenever the Gosub name command is executed, the statements between the matching Subroutine name and the EndSub are executed. Note that "name" can be anything you desire.
booleanExpression
A boolean expresion consists of a numericalExpression, a conditional operation, and another numericalExpression. The numericalExpression can be a number or any variable. The conditional operations are <, <=, =, !=, >=, >, which mean less than, less than or equal to, equal to, not equal to, greater than or equal to, and greater than.
General Commands
Here are the commands. "n" represents a numericalExpression.
splitLine
Splits the current line in half. The current line is set to the first half.
segmentLine n
Adds an n sized segment to the center of the current line. Becomes the current line.
turn n
Turns the pen by n degrees.
newLine n
Creates a new line from the current point n units long.
closePoly
Creates a new line from the current point to the first point in the poly.
height n
Sets the ceiling height to the floor height plus n.
ceilingHeight n
Changes the ceiling height by n units.
floorHeight n
Changes the floor height by n units.
ceilingMode n
Sets the default ceiling draw mode to n.
floorMode n
Sets the default floor draw mode to n.
polyType n
Sets the default polygon type to n.
wallType n
Sets the wall type for the next wall to n. This is for control panels.
wallMode n
Sets the default wall draw mode to n.
pushPen
Saves the current pen position and angle.
popPen
Returns to the last saved pen position and angle.
pushLine
Saves the current line.
popLine
Returns to the last saved line and makes it the selected line.
ClosePoly must have been called first. Also makes a point at the first point.
move n
Moves the pen without creating a side.
makeLine
Creates a new side from the last point to the current pen position.
*
The rest of the line is ignored.
firstPoint
Moves the pen to the first point on the selected line.
lastPoint
Moves the pen to the last point on the selected line.
set variableName n
Sets the variable specified to the value of n.
add variableName n
Adds n to the specified variable.
divide variableName n
Divides the specified variable by n.
multiply variableName n
Multiplys the specified variable by n.
Debug 0 or 1
If debug is set to 1, then each line of script that is executed is written to the file "Script Output".
You can set debug to 0 to stop the output of debug info.
Call fileName
This will execute all the commands in the script file specified.
AskUser text
This will display a dialog with the specified text in it allowing the user to enter a number.
The number will be stored in the variable "Result".
numericalExpressions
Numerical expressions can be a number or a variable name with an optional leading '-' to indicate a negative number or variable. You can use these variables anywhere a number is expected. In most cases, you can also set these variables.
LineLength
The length of the selected line.
StairSize
The value for the step size in the defaults palette.
LeftSize
The value for the left size in the defaults palette.
RightSize
The value for the right size in the defaults palette.
OrigLineLength
The length of the selected line when the user first caused this script to execute.
OrigAngle
The angle of the pen when the user first caused this script to execute.
OrigFloorHeight
The floor height of the poly when the user first caused this script to execute.
OrigCeilingHeight
The ceiling height of the poly when the user first caused this script to execute.
Angle
The current angle of the pen.
DefaultFloorHeight
The floor height in the defaults palette.
DefaultCeilingHeight
The ceiling height in the defaults palette.
FloorHeight
The height of the floor for the next poly created.
CeilingHeight
The height of the ceiling for the next poly created.
Random n
A random number between 0 and n - 1.
Result
The value the user entered in the AskUser dialog box.
A, B, C, D
These are general purpose variables for your own use.
Special Numerical Values
These values are only useful in special cases, like setting poly types etc.